package models

import "gorm.io/gorm"

type Video struct {
	gorm.Model
	Title       string `gorm:"type:varchar(20);index;not null;comment:视频标题"`
	TypesId     int64  `gorm:"type:int;not null;comment:分类ID"`
	CoverUrl    string `gorm:"type:varchar(200);not null;comment:封面地址"`
	PlayUrl     string `gorm:"type:varchar(200);not null;comment:文件地址"`
	CheckStatus int64  `gorm:"type:int;default:0;comment:审核状态0-待审核 1-审核中 2-通过 3-驳回"`
	CheckReason string `gorm:"type:varchar(20);comment:审核备注"`
}

func (v *Video) CreateVideo(db *gorm.DB) error {
	return db.Create(&v).Error
}

func (e *Video) GetVideoById(db *gorm.DB, id int64) error {
	return db.Where("id=?", id).Limit(1).Find(&e).Error
}

// 审核状态修改
func (v *Video) UpdateCheckStatus(db *gorm.DB, id, status int64) error {
	return db.Model(&v).Where("id=?", id).Update("check_status", status).Error
}

// 电视剧表
type Episode struct {
	gorm.Model
	IsVip     int64  `gorm:"type:tinyint;default:0;comment:0-免费,1-收费"`
	Title     string `gorm:"type:varchar(20);not null;comment:视频标题"`
	AuthorId  int64  `gorm:"type:int;comment:制片方ID"`
	TypesId   int64  `gorm:"type:int;comment:分类ID"`
	EpisodeNo int64  `gorm:"type:int;default:0;comment:剧集数"`
	PlayCount int64  `gorm:"type:int;default:0;comment:播放量"`
}

func (e *Episode) CreateEpisode(db *gorm.DB) error {
	return db.Create(&e).Error
}

func (e *Episode) GetEpsById(db *gorm.DB, id int64) error {
	return db.Where("id=?", id).Limit(1).Find(&e).Error
}

// 更新视频播放数
func (e *Episode) UpdateEpisodePlay(db *gorm.DB) error {
	return db.Model(&e).
		Where("id =?", e.ID).
		Update("play_count", gorm.Expr("play_count + ?", 1)).
		Error
}
